package com.fyzk.activity.trend;

import com.tyjc.lottery.R;
import com.fyzk.utils.LogUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanxs11 on 2017/7/16.
 */

public class SSCTrendBean extends TrendBean{
    @Override
    public List<List<String>> getMissValues(int payType, int chooseId, String missTitle, String hcTitle) {
        List<List<String>> missValues = new ArrayList<>();
        if (issues == null || issues.size() == 0 || misses == null || misses.size() == 0 || hcs == null || hcs.size() == 0) {
            return missValues;
        }

        switch (chooseId) {
            case R.id.trend_choose_rb1:     // 第一个选项卡——开奖
                for (int i = 0; i < issues.size(); i++) {
                    IssuesBean issuesBean = issues.get(i);
                    List<String> missNums = new ArrayList<>();
                    missNums.add(issuesBean.getWincode());  // 开奖号码
                    missNums.add(issuesBean.getAndValue());      // 和值
                    missNums.add(issuesBean.getSpanValue());     // 跨度
                    missValues.add(missNums);
                }
                return missValues;
            case R.id.trend_choose_rb2:     // 第二个选项卡——走势
            case R.id.trend_choose_rb5:     // 第二个选项卡——走势
            case R.id.trend_choose_rb6:     // 第二个选项卡——走势

                return getZouShi(missTitle);
            case R.id.trend_choose_rb3:
                switch (payType) {
                    case 7:     // 前二直选走势
                    case 8:    // 前三直选走势

                        return getZouShi(missTitle);
                    default:    // 冷热数据

                        HcsBean hcsBean30 = hcs.get(0);
                        HcsBean hcsBean50 = hcs.get(1);
                        HcsBean hcsBean100 = hcs.get(2);
                        // 最新期遗漏
                        List<String> zouShiMiss = getOneZouShi(misses.size()-1,missTitle);

                        for (int i = 0; i < 10; i++) {

                            List<Integer> hcs30Misses = hcsBean30.getHcValues(hcTitle);
                            List<Integer> hcs50Misses = hcsBean50.getHcValues(hcTitle);
                            List<Integer> hcs100Misses = hcsBean100.getHcValues(hcTitle);

                            List<String> missNums = new ArrayList<>();
                            try {
                                missNums.add(hcs30Misses.get(i)+"");    // 30期冷热
                                missNums.add(hcs50Misses.get(i)+"");    // 50期冷热
                                missNums.add(hcs100Misses.get(i)+"");   // 100期冷热
                            } catch (IndexOutOfBoundsException e) {
                                LogUtil.d(e.getMessage());
                            }

                            if (i < zouShiMiss.size()) {
                                missNums.add(zouShiMiss.get(i));
                            } else {
                                missNums.add("-");
                            }

                            missValues.add(missNums);
                        }
                        this.maxMiss[0] = hcsBean30.maxHc+"";
                        this.maxMiss[1] = hcsBean50.maxHc+"";
                        this.maxMiss[2] = hcsBean100.maxHc+"";
                        return missValues;
                }
            case R.id.trend_choose_rb4:
                switch (payType) {
                    case 3:    // 前三直选走势
                    case 7:    // 前三直选走势
                    case 8:    // 前三直选走势

                        return getZouShi(missTitle);
                    default:    // 形态数据

                        for (int i = 0; i < issues.size(); i++) {
                            IssuesBean issuesBean = issues.get(i);
                            List<String> missNums = new ArrayList<>();
                            missNums.add(issuesBean.getWincode());       // 开奖号码
                            missNums.add(issuesBean.getBigsmall());      // 大小比
                            missNums.add(issuesBean.getOddEvenValue());  // 奇偶比
                            missNums.add(issuesBean.getPrimeValue());    // 质合比
                            missValues.add(missNums);
                        }
                        return missValues;
                }

            default:
                break;
        }

        return missValues;
    }

    @Override
    protected List<List<String>> getZouShi(String missTitle) {
        List<List<String>> missValues = new ArrayList<>();
        int rowCount = 0;
        if (misses.size() > 0) {
            rowCount = misses.get(0).getMissValues(missTitle).size();
        }
        int[] showCounts = new int[rowCount];
        int[] averageMiss = new int[rowCount];
        int[] maxMiss = new int[rowCount];
        int[] maxLianMiss = new int[rowCount];
        int[] lian = new int[rowCount];
        for (int x = 0; x < lian.length; x++) {
            lian[x] = 1;
        }

        for (int i = 0; i < misses.size(); i++) {
            MissesBean missesBean = misses.get(i);
            List<String> missNums = new ArrayList<>();
            List<Integer> missVs = missesBean.getMissValues(missTitle);
            List<Integer> missVs2 = missVs;
            MissesBean missesBean2;
            if (i > 0) {
                missesBean2 = misses.get(i-1);
                missVs2 = missesBean2.getMissValues(missTitle);
            }

            for (int j = 0; j < missVs.size(); j++) {
                missNums.add(missVs.get(j)+"");

                // 统计
                if (missVs.get(j) == 0) {
                    showCounts[j]++;
                }
                if (i > 0 && missVs.get(j) == 0) {
                    averageMiss[j] += missVs2.get(j);
                }
                if (i == misses.size()-1) {
                    averageMiss[j] += missVs.get(j);
                }
                if (missVs.get(j) > maxMiss[j]) {
                    maxMiss[j] = missVs.get(j);
                }
                if (i > 0) {
                    if (missVs2.get(j) == missVs.get(j)) {
                        lian[j]++;
                    } else {
                        lian[j] = 1;
                    }
                    if (maxLianMiss[j] < lian[j]) {
                        maxLianMiss[j] = lian[j];
                    }
                }
            }

            missValues.add(missNums);
        }

        List<String> showCounts_list = new ArrayList<>();
        List<String> averageMiss_list = new ArrayList<>();
        List<String> maxMiss_list = new ArrayList<>();
        List<String> maxLianMiss_list = new ArrayList<>();

        for (int i = 0; i < showCounts.length; i++) {
            showCounts_list.add(showCounts[i]+"");
            int average;
            if (showCounts[i] == 0) {
                average = maxMiss[i];
            } else {
                average = averageMiss[i]/(showCounts[i]+1);
//                if (average == 0) {
//                    average = 1;
//                }
            }
            averageMiss_list.add(average+"");
            maxMiss_list.add(maxMiss[i]+"");
            if (showCounts[i] == 0) {
                maxLianMiss[i] = 0;
            }
            maxLianMiss_list.add(maxLianMiss[i]+"");
        }

        missValues.add(showCounts_list);	// 出现次数
        missValues.add(averageMiss_list);	// 平均遗漏
        missValues.add(maxMiss_list);		// 最大遗漏
        missValues.add(maxLianMiss_list);	// 最大连出
        return missValues;
    }
}
